package com.zty.xiaomiadmin.server.Service.ServiceOrder;

import com.zty.xiaomiadmin.server.Dao.ServiceOrderMapper;
import com.zty.xiaomiadmin.server.Dao.category;
import com.zty.xiaomiadmin.server.Entity.ServiceOrder.ServiceOrder;
import com.zty.xiaomiadmin.server.utils.SqlSessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.List;

@Service
@Transactional
public class ServiceOrderServiceImp implements ServiceOrderService {


    @Override
    public List<ServiceOrder> getServiceOrderByStatusAndStoreId(int pageIndex,int pageSize,int status,int store_id) throws IOException {

        return SqlSessionUtil.getSqlSessionInstance().getSqlSession()
                .getMapper(ServiceOrderMapper.class).getServiceOrderByStatusAndStoreId(pageIndex, pageSize, status, store_id);
    }

    @Override
    public List<ServiceOrder> getServiceOrderByStoreId(int pageIndex, int pageSize, int store_id) throws IOException {
        return SqlSessionUtil.getSqlSessionInstance().getSqlSession()
                    .getMapper(ServiceOrderMapper.class).getServiceOrderByStoreId(pageIndex, pageSize,store_id);
    }

    @Override
    public int countServiceOrderByStatusAndStoreId(int status, int store_id) throws IOException {
        return SqlSessionUtil.getSqlSessionInstance().getSqlSession()
                .getMapper(ServiceOrderMapper.class).countServiceOrderByStatusAndStoreId(status,store_id);
    }

    @Override
    public int countServiceOrderByStoreId(int store_id) throws IOException {
        return SqlSessionUtil.getSqlSessionInstance().getSqlSession()
                .getMapper(ServiceOrderMapper.class).countServiceOrderByStoreId(store_id);
    }


    @Override
    public List<ServiceOrder> getServiceOrder(int pageIndex,int pageSize) throws IOException {
        return SqlSessionUtil.getSqlSessionInstance().getSqlSession()
                .getMapper(ServiceOrderMapper.class).getServiceOrder(pageIndex, pageSize);
    }

    @Override
    public int updateServiceOrderStatusById(int id, int status, String store_reply) throws IOException {
        int num = SqlSessionUtil.getSqlSessionInstance().getSqlSession()
                .getMapper(ServiceOrderMapper.class).updateServiceOrderById(id, status, store_reply);
        if (num == 1) {
            SqlSessionUtil.getSqlSessionInstance().getSqlSession().commit();
        } else {
            SqlSessionUtil.getSqlSessionInstance().getSqlSession().rollback();
        }
        return num;
    }
}
